package com.lin;

import sun.text.normalizer.UCharacter;

import java.util.*;

public class Solution976Test {
    public static boolean isPossible(int[] nums){
        Map<Integer, PriorityQueue<Integer>> map = new HashMap<Integer, PriorityQueue<Integer>>();
        for (int num : nums) {
            if (!map.containsKey(num)){
                map.put(num, new PriorityQueue<>());
            }
            if(map.containsKey(num-1)){
                int length = map.get(num).poll();
                if (map.get(num-1).isEmpty()){
                    map.remove(num-1);
                }
                map.get(num).offer(length+1);
            }else {
                map.get(num).offer(1);
            }
        }
        for (Map.Entry<Integer, PriorityQueue<Integer>> integerPriorityQueueEntry : map.entrySet()) {
            PriorityQueue<Integer> queue = integerPriorityQueueEntry.getValue();
            if (queue.peek()<3){
                return false;
            }
        }
        return true;
     }
}
